import { Color } from "cc"
import { Game_Status } from "../../common/enums"
import { convertToMap } from "../../../platform/utils/TypeUtil"

export class Game2048Model{

    nowPoint:number = 0
    row:number = 4
    col:number = 4
    level:number = 0
    //棋盘数据
    boardData:number[][] = []
    //滑动的总次数
    moveTotalTimes:number = 0
    //总时间
    totalTime:number = 0
    //每个方向滑动的次数：0上，1下，2左，3右
    directionTimes:Map<number,number> = new Map()
    //合成每个数字的次数
    numberTimes:Map<number,number> = new Map()
    //随机棋盘次数(棋盘数据重新随机摆位置)
    randomTimes:number = 0
    //是否已经合成过1024了
    passed = false
    //游戏状态
    gameState:Game_Status = Game_Status.Uninit
    resetData(data: any) {
        let localData = data as Game2048Model
        if(localData.nowPoint){
            this.nowPoint = localData.nowPoint
        }
        if(localData.boardData){
            this.boardData = localData.boardData
        }
        if(localData.moveTotalTimes){
            this.moveTotalTimes = localData.moveTotalTimes
        }
        if(localData.totalTime){
            this.totalTime = localData.totalTime
        }
        if(localData.directionTimes){
            this.directionTimes = convertToMap(localData.directionTimes)
        }
        if(localData.numberTimes){
            this.numberTimes = convertToMap(localData.numberTimes)
        }
        if(localData.randomTimes){
            this.randomTimes = localData.randomTimes
        }
        if(localData.gameState){
            this.gameState = localData.gameState
        }
    }
}